import { getToken, setToken, removeToken } from '@/utils/auth'
const state = {
  token: getToken()
}

const mutations = {
  setToken(state, token) {
    // 设置到vuex中
    state.token = token
    // 设置到本地存储coolie中
    setToken(token)
  },
  // 删除vuex以及本地的token
  removeToken(state, token) {
    state.token = null
    removeToken
  }
}

const actions = {
  async login(context, data) {
    console.log(data)
    const token = '123456'
    context.commit('setToken', token)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
